package com.example.demomybatis.controller;


import com.alibaba.fastjson.JSON;
import com.example.demomybatis.entity.Student;
import com.example.demomybatis.service.IStudentService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhaoheng
 * @since 2023-07-08
 */
@RestController
@RequestMapping("/student")
@Slf4j
public class StudentController {
    @Resource
    IStudentService iStudentService;

    @ApiOperation("新增student")
    @PostMapping("save")
    public String save(@RequestBody Student student) {
        log.info("student:{}", JSON.toJSONString(student));
        boolean b = iStudentService.saveOrUpdateByMultiId(student);
        if (b) {
            return "创建成功";
        } else {
            return "创建失败";
        }
    }

    @ApiOperation("根据姓名集合查询")
    @GetMapping("queryByNames")
    public List<Student> query(@RequestParam(value = "names") List<String> names) {
        log.info("查询条件：{}", JSON.toJSONString(names));
        return iStudentService.queryByNames(names);
    }

    @ApiOperation("更新用户生日")
    @PostMapping("udpateBirthday")
    public String update(@RequestParam @ApiParam(value = "id") String id, @RequestParam @ApiParam(value = "birthday,yyyyMMddHHmmss") String birthday) {
        return iStudentService.updateBirthday(id, birthday);
    }

}
